package com.ruoyi.laboratory.strategy.exptimpt;

import com.ruoyi.common.core.utils.exptimpt.AbstractExImportStrategy;
import com.ruoyi.common.core.utils.exptimpt.ExImportHandlerChain;
import com.ruoyi.common.core.utils.exptimpt.validator.ValidatorChainForBusiness;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.laboratory.domain.LabResearchProject;
import com.ruoyi.laboratory.domain.excel.LabResearchProjectExcel;
import com.ruoyi.laboratory.enums.ExImportBusinessEnum;
import com.ruoyi.laboratory.service.ILabResearchProjectService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author huangliang
 * @date 2024-09-04 17:54
 * @description 默认导入导出具体策略
 */
@Component
public class ExImportStrategyResearchProject extends AbstractExImportStrategy<LabResearchProjectExcel> {

    @Resource
    private ILabResearchProjectService labResearchProjectService;

    public ExImportStrategyResearchProject() {
        super(new ExcelUtil<>(LabResearchProjectExcel.class), ExImportBusinessEnum.PROJECT,
                //看具体情况增加校验器
                ExImportHandlerChain.link(
//                        new ValidatorChainDictData(),
                        new ValidatorChainForBusiness()
                )
                ,
                null
//                ExImportHandlerChain.link(
//                        new ConversionChainDictData()
//                )
        );
    }

    @Override
    public Integer insertData() {
        List<LabResearchProject> labResearchProjects = LabResearchProjectExcel.coverToDOList(dataList);
        labResearchProjectService.saveBatch(labResearchProjects);
        return labResearchProjects.size();
    }
}
